home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- // Copyright (C) 1997-1999 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- // Creation Date: Mar. 14, 1997
- //
- //<doc>
- //<name executeForEachObject>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<synopsis>
- // string[] executeForEachObject( string $inThisList[], string $thisCmd )
- //
- //<description>
- // This procedure takes a list of object names and applies the
- // command in "thisCmd" to each object. The object name is
- // substituted for a %s in the command.
- //
- //<flags>
- // string $inThisList[] - a list of object names to operate on
- // string $thisCmd - a string with %s in it.
- //
- //<returns>
- // An array of strings is returned containing
- // the names of all results from executing this command on each
- // applicable object.
- //
- //<examples>
- //
- // Example 1. if "thisCmd" is a string that looks like:
- // reverseCommand -ch off -rpo on %s;
- // and curve1 and curve2 are in the given list, then the commands
- // that will be executed for each object will look like:
- // reverseCommand -ch off -rpo on curve1;
- // reverseCommand -ch off -rpo on curve2;
- //
- // Example 2. if "thisCmd" is a string that looks like:
- // reverseProc( true, false, %s );
- // and curve1 and curve2 are in the given list, then the commands
- // that will be executed for each object will look like:
- // reverseProc( true, false, curve1 );
- // reverseProc( true, false, curve2 );
- //
- // Example 3.
- // cone; sphere; select -all;
- // string $cmd = "duplicate %s";
- // string $itemList[] = `ls -sl`;
- // select -d;
- // string $results[] = executeForEachObject($itemList, $cmd);
- //
- //</doc>
- //
- global proc string[] executeForEachObject(
- string $inThisList[], string $thisCmd )
- {
- string $listOfExecutedObjects[];
- string $results[];
- int $numExecutions = 0;
- int $numObjects = size($inThisList);
- if( $numObjects > 0 ) {
- int $i;
- string $tmp;
- for( $i=0; $i<$numObjects; $i+=1 ) {
- if ( "" == $inThisList[$i] ) {
- $tmp = `substitute "%s" $thisCmd $inThisList[$i]`;
- }
- else {
- $tmp = `substitute "%s" $thisCmd ("\"" + $inThisList[$i] + "\"")`;
- }
- if( !catch( $results = evalEcho( $tmp ) )) {
- $numExecutions ++;
- int $numResults = size( $results );
- int $numExec = size( $listOfExecutedObjects );
- for( $n = 0; $n < $numResults; $n ++ ) {
- $listOfExecutedObjects[$numExec + $n] = $results[$n];
- }
- }
- }
- }
- return $listOfExecutedObjects;
- }
-